package com.im.nero.teacher.struts;

import java.util.ArrayList;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.im.nero.teacher.entity.Question;
import com.opensymphony.xwork2.ActionSupport;

public class makeQuizAction extends ActionSupport implements SessionAware{

		


	private Map<String, Object> sessionMap;
	private String name,category, time,num;
	private String Q, A1,A2,A3,A4,cardtype;
	private int counter;
	private ArrayList<Question> QuestionCollection;
	
		
		public String makeQuizInfo(){
			
			
			
			System.out.println("INFO: "+name+" "+category+" "+time+" "+num);
			

	
			
			QuestionCollection= new ArrayList<Question>();
			counter=0;
			
			sessionMap.put("quizName", name);
			sessionMap.put("questionCollection", QuestionCollection );
			sessionMap.put("counter", counter );
			
			return "info";
		}
		
		public String makeQuizList(){
			
			System.out.println("LIST: "+Q+" :"+A1+" "+A2+" "+A3+ " "+A4+ " "+cardtype);
			Question q=new Question();
		
				
				//q.setqNumber((counter+1));
				q.setA1(A1);
				q.setA2(A2);
				q.setA3(A3);
				q.setA4(A4);
				q.setQ(Q);
				q.setStrR(cardtype);
				q.setIntR(Integer.parseInt(cardtype));
		
			
			
			 if (sessionMap.containsKey("questionCollection")) {
				// System.out.println("fuckkk");
				 System.out.println("Session OK");
		           QuestionCollection=(ArrayList<Question>)sessionMap.get("questionCollection");
		           if(QuestionCollection!=null){
		        	   QuestionCollection.add(q);		        	   
		           }else{
		        	   QuestionCollection=new ArrayList<Question>();
		        	   QuestionCollection.add(q);
		           }
		          
		           sessionMap.put("questionCollection", QuestionCollection);
		           counter=QuestionCollection.size();
		           sessionMap.put("counter", counter);
		           System.out.println("counter :"+counter);
		           
		           for (int i = 0; i < QuestionCollection.size(); i++) {
		        	   System.out.println(QuestionCollection.get(i).getQ());
				}
		          
		        }
			
		

			return "list";
		}	



		@Override
		public void setSession(Map<String, Object> sessionMap) {
			this.sessionMap=sessionMap;
			
		}
		
		
		
		
		
		
		
		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getCategory() {
			return category;
		}

		public void setCategory(String category) {
			this.category = category;
		}

		public String getTime() {
			return time;
		}

		public void setTime(String time) {
			this.time = time;
		}

		public String getNum() {
			return num;
		}

		public void setNum(String num) {
			this.num = num;
		}

		
		
		
		
		
		

		public String getCardtype() {
			return cardtype;
		}

		public void setCardtype(String cardtype) {
			this.cardtype = cardtype;
		}
		public String getQ() {
			return Q;
		}

		public void setQ(String q) {
			Q = q;
		}

		public String getA1() {
			return A1;
		}

		public void setA1(String a1) {
			A1 = a1;
		}

		public String getA2() {
			return A2;
		}

		public void setA2(String a2) {
			A2 = a2;
		}

		public String getA3() {
			return A3;
		}

		public void setA3(String a3) {
			A3 = a3;
		}

		public String getA4() {
			return A4;
		}

		public void setA4(String a4) {
			A4 = a4;
		}


		public int getCounter() {
			return counter;
		}


		public void setCounter(int counter) {
			this.counter = counter;
		}
		
		public ArrayList<Question> getQuestionCollection() {
			return QuestionCollection;
		}

		public void setQuestionCollection(ArrayList<Question> questionCollection) {
			QuestionCollection = questionCollection;
		}

}
